﻿namespace UnityEditor.Scripting.Compilers
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.IO;
    using UnityEditor.Scripting;
    using UnityEditor.Utils;

    internal class MicrosoftCSharpCompiler : ScriptCompilerBase
    {
        public MicrosoftCSharpCompiler(MonoIsland island) : base(island)
        {
        }

        protected override CompilerOutputParserBase CreateOutputParser()
        {
            return new MicrosoftCSharpCompilerOutputParser();
        }

        protected override string[] GetStreamContainingCompilerMessages()
        {
            return base.GetStandardOutput();
        }

        protected override Program StartCompiler()
        {
            List<string> arguments = new List<string> {
                "/debug:full",
                "/optimize-",
                "/debug+",
                "/target:library",
                "/nowarn:0169",
                "/out:" + ScriptCompilerBase.PrepareFileName(this._island._output)
            };
            foreach (string str in this._island._references)
            {
                arguments.Add("/reference:" + ScriptCompilerBase.PrepareFileName(str));
            }
            foreach (string str2 in this._island._defines)
            {
                arguments.Add("/define:" + str2);
            }
            foreach (string str3 in this._island._files)
            {
                arguments.Add(ScriptCompilerBase.PrepareFileName(str3).Replace('/', '\\'));
            }
            string str5 = Path.Combine(Environment.GetEnvironmentVariable("windir"), @"Microsoft.NET\Framework\v4.0.30319\Csc.exe");
            base.AddCustomResponseFileIfPresent(arguments, "csc.rsp");
            string str6 = CommandLineFormatter.GenerateResponseFile(arguments);
            ProcessStartInfo si = new ProcessStartInfo {
                Arguments = "@" + str6,
                FileName = str5
            };
            Program program = new Program(si);
            program.Start();
            return program;
        }
    }
}

